<?php
class ShortlistController extends Controller {
    
    public $defaultAction='Category';
    
    public function accessRules(){
        return array(
            array('allow',
                'users'=>array('@'),
            ),
            array('deny'),
        );
    }
    
    public function actions() {
        return array(
            'shortlistItem'=>array(
                'class'=>'ext.widgets.EShortlist.ShortListAction',
                'module'=> 'Item',
                'moduleId'=>Yii::app()->request->getParam('id'),
            ),
            'likeItem'=>array(
                'class'=>'ext.widgets.ELike.LikeAction',
                'module'=> 'Item',
                'moduleId'=>Yii::app()->request->getParam('id'),
            ),
            'abuseItem'=>array(
                'class'=>'ext.widgets.EAbuse.AbuseAction',
                'module'=> 'Item',
                'moduleId'=>Yii::app()->request->getParam('id'),
            ),
        );
    }
    
    public function init(){
        parent::init();
        
        switch(Yii::app()->user){
            case Yii::app()->user->isMerchant:
                $this->breadcrumbs = array(
                    Lang::t('merchant.page.breadcrumbs') => Yii::app()->createUrl('merchant/site/index'),
                );
                break;
            default:
                $this->breadcrumbs = array(
                    Lang::t('user.page.breadcrumbs') => Yii::app()->createUrl('user/site/index'),
                );
                break;
        }
    }
    
    public function actionIndex(){
        
        $this->render('index',array(
            
        ));
    }
    
    public function actionCategory(){
        
        $model=new Category();
        $model->userId_=Yii::app()->user->id;
        $this->render('category', array(
            'dataProvider'=>$model->findAllShortlisted(),
        ));
    }
    
    public function actionItem($id){
        
        $this->breadcrumbs += array(
            Lang::t('shortlist.category.page.breadcrumbs') => Yii::app()->createUrl('user/shortlist'),
        );
        
        $data=Category::model()->published()->findByPk($id);
        if(empty($data)) HttpStatus::code(404);
        
        $model=new Item('shorlistSearch');
        $model->userId_=Yii::app()->user->id;
        $model->category_=$id;
        
        $this->render('item', array(
            'dataProvider'=>$model->findAllShortlisted(),
            'data'=>$data,
        ));
    }
    
}